# Contributor: Marian <marian.buschsieweke@ovgu.de>
# Maintainer: Marian <marian.buschsieweke@ovgu.de>
pkgname=afl++
pkgver=4.07c
pkgrel=1
pkgdesc="Fuzzer relying on genetic algorithms instead of brute force"
url="https://aflplus.plus/"
# s390x: blocked by missing lld
# x86: basic unit tests fails
# 32-bit: unlikely anyone is doing fuzzing here
arch="all !armhf !armv7 !s390x !x86"
license="Apache-2.0"
# afl-cmin requires stat
_llvmver=17
depends="
	clang$_llvmver
	compiler-rt
	lld~$_llvmver
	llvm$_llvmver
	python3
	"
# install -T
makedepends="
	clang$_llvmver-dev
	coreutils
	gmp-dev
	grep
	llvm$_llvmver-dev
	python3-dev
	"
checkdepends="
	bash
	cmocka-dev
	"
subpackages="$pkgname-doc"
provides="
	afl=$pkgver-r$pkgrel
	afl-clang=$pkgver-r$pkgrel
	afl-gcc=$pkgver-r$pkgrel
	"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/AFLplusplus/AFLplusplus/archive/refs/tags/$pkgver.tar.gz

	0001-fix-missing-max-path-define.patch
	0003-fix-wrong-format-specifier.patch
	0004-busybox-stat.patch
	0005-ignore-broken-test.patch
	"
builddir="$srcdir/AFLplusplus-$pkgver"

build() {
	export PATH="$PATH:/usr/lib/llvm$_llvmver/bin"
	export NO_NYX=1
	export AFL_NO_X86=1
	export LLVM_LTO=1
	make PREFIX=/usr all
}

check() {
	# Unset our CFLAGS/CXXFLAGS for the tests since these may
	# interact in unexpected ways with afl-cc instrumentation.
	CFLAGS= CXXFLAGS= make AFL_NO_X86=1 test
}

package() {
	make AFL_NO_X86=1 PREFIX=/usr DESTDIR="$pkgdir" install

	# Test cases contain x86 binaries that cause trouble with strip on non-x86
	# architectures, so just drop the test cases here.
	rm -rf "$pkgdir"/usr/share/afl/testcases/
}

sha512sums="
c62fce112d59ef5ffb847adab9a7ff8486d44e6316a391392979da19a8160b55f9af7f75fd39cdc98997b3e166f4f6a33ddf31b827c9414a1392657701ecb5e8  afl++-4.07c.tar.gz
f12285163797823d820029b7bc4591fa040aac137724611e3643a77fcf49f04f59efb0e2e95863966636299dd92862bc5319d4434d4543289dfb8392dc39b97a  0001-fix-missing-max-path-define.patch
29063f71feff74bb7c74d7e11da654d120d76b178532321ee6c40bf766e3a8834cc09458fc0afdade96c2119fb2fbbb5fd8e01ae5df08ea615688872797380e1  0003-fix-wrong-format-specifier.patch
4a00b4c5a494d06896746e5c5dac93f736efa60a51bcc659adec6ec1c928804af6b3f401a41aaf99451ea7c1611607691deea879b41d3b607c1a9fc41aa914f0  0004-busybox-stat.patch
b407c86a33419a323db94cc97a3333d1afe7d77eb04a4b4182d0b4cdc9ea2a23bbada61f912f2f6ba6d84924f6d0137894644d400caf29b447e6cf8a046ec290  0005-ignore-broken-test.patch
"
